<template>
  <div class="cinemas" v-if="Details">
    <div class="film-header">
      <div class="goBack" @click="$router.go(-1)">
        <i class="iconfont icon-zuobian-copy"></i>
      </div>
      <div class="title" :class="[show?'activeb':'activec']">
        <span v-show="show">{{Details.name}}</span>
      </div>
    </div>
    <div class="cinemas_bg" :style="{backgroundImage:'url('+Details.poster+')'}"></div>
    <div class="film-detail">
      <div class="col">
        <div class="film-name">
          <span class="name">{{Details.name}}</span>
          <span class="item">{{Details.filmType.name}}</span>
        </div>
        <div class="film-grade">
          <span class="grade">{{Details.grade}}</span>
          <span class="grade-text">分</span>
        </div>
      </div>
      <div class="film-category grey-text">{{Details.category}}</div>
      <div class="film-premiere-time grey-text">{{Rtime(Details.premiereAt)}}上映</div>
      <div class="film-nation-runtime grey-text">{{Details.nation}} | {{Details.runtime}}分钟</div>
      <div class="film-synopsis grey-text" :class="down?'':'box-active'" style="line-height:20px;">{{Details.synopsis}}</div>
      <div class="toggle" @click="down=!down">
        <img src="./x.png" alt="" :class="down?'arrowDown':'arrowRight'"/>
      </div>
    </div>
    <div class="actors">
      <div class="actors-title-bar">
        <span>演职人员</span>
      </div>
      <div class="slide-box" >
        <div v-for="(n,index) in Details.actors" :key="index">
          <div class="slide-item">
            <img :src="n.avatarAddress" alt="">
          </div>
          <div class="name">
            <p>{{n.name}}</p>
            <p class="actors-role">{{n.role}}</p>
          </div>
        </div>
      </div>
    </div>

    <div class="photos">
      <div class="photos-title-bar">
        <span class="photos-title-text">剧照</span>
        <span class="claphotos-to-all" @click="whole">
          全部(5)
          <i class="iconfont icon-xiangyou1"></i>
        </span>
      </div>
      <div class="slide-box">
          <div class="slide-item" v-for="(t, index) in Details.photos" :key="index" >
            <img :src="t" alt="" @click="getImg(t,index)">
          </div>
      </div>
      <div class="goSchedule" @click="purchase(Details.filmId)">选座购票</div>
    </div>
    <teleport to='body'>
    <div class="overlay" v-if="overlay">
      <div class="film-header">
        <i class="iconfont icon-zuobian-copy" @click="showClick"></i>
        <span>剧照(5)</span>
      </div>
      <div class="all-photos">
       <div class="lazy-img" v-for="(t, index) in Details.photos" :key="index">
           <img :src="t" alt="" @click="getImg(t,index)">
       </div>
      </div>
    </div>
  </teleport>
  </div>
  
</template>

<script>
import { reactive, toRefs } from '@vue/reactivity';
import { computed, onMounted } from 'vue';
import { ImagePreview } from 'vant';
import { DetailsDataAPI } from '@/api'
import { useRoute, useRouter } from 'vue-router';
import { useStore } from 'vuex';
export default {
  name:'Cinemas',
  setup(props) {
    const root = reactive({
      show:false,
      down:false,
      overlay:false,
      Details:null,
      time:'',
      styleObj:{
        background:"black",
    }
    })
    const route = useRoute();
  
    onMounted(()=>{
      DetailsList()
      window.addEventListener('scroll',handleScroll,true);
    })

    const handleScroll =()=>{
      let scrollTop = document.documentElement.scrollTop;
      scrollTop>60?root.show=true:root.show=false
    }
    
    const getImg = (t,index)=>{
        ImagePreview({
        images:root.Details.photos, 
        loop:false,   
        startPosition:index,  
        closeable: true,
        closeIconPosition:'top-left',
        overlayStyle:root.styleObj
      })
    }

    const DetailsList = async ()=> {
      const { data:res } = await DetailsDataAPI({id:route.params.id});
      if (res.msg == 'ok') {
        root.Details=res.data.film
      }
    }
    
    const Rtime = computed(()=>{
      return function(id){
       let data = new Date(id*1000)
       let y = data.getFullYear()//年
       let MM = data.getMonth() + 1
       MM= MM<10?('0'+MM):MM
       let d = data.getDate()
       d=d<10?('0'+d):d
       return  y+'-'+MM+'-'+d
      }
    })

    const router = useRouter();
    const store = useStore();
    const purchase = (id)=>{
        // router.push(`/cinemas/${id}/fiml`)
        router.push({
          name:'cinemas',
          //  path:'/cinemas/:id/fiml',
          params:{
            cinemaId:id
          }
        })

        store.commit('MovieName',root.Details.name)
    }

    // 全部剧照
    const whole = ()=>{
      root.overlay=true
    }

    const showClick = ()=>{
      root.overlay=false
    }


    return {
      ...toRefs(root),
      getImg,
      whole,
      showClick,
      Rtime,
      purchase
    }
  }
};
</script>

<style lang="less" scoped>

//遮罩
.overlay{
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  background: white;

  & .film-header{
    width: 100%;
    text-align: center;
    position: relative;
    line-height: 44px;

    & .iconfont{
      position: absolute;
      left: 10px;
    }
  }
  & .all-photos{
    display: flex;
    width: 100%;
    flex-wrap: wrap;
   
    & .lazy-img{
      width: calc(100% / 3);
      height: calc(33.33333vw - 1px);
      padding: 1px;

      img{
        width: 100%;
        height: 100%;

      }
    }
  }
}




// 小图标
.arrowDown{
  cursor: pointer;
  transition: 0.1s;
  transform: rotateZ(180deg);
 
}
.arrowRight{
  transition: 0.1s;
  transform-origin: center;
  transform: rotateZ(0deg);
}
//详情
.box-active {
  overflow:hidden;
  height:38px; 
  transition: all 2s;
}

//头部
.activec{
  opacity: 1;
  transition: all 0.7s;
}
.activeb{
  background: white;
  transition: all 0.7s;
  opacity: 1;
}


.cinemas{
  padding-bottom: 60px;
}
.cinemas_bg {
  width: 100%;
  height: 56vw;
  background-position: 100%;
  background-repeat: no-repeat;
  background-size: 100%;
}


.film-detail {
  padding: 15px;
  background: white;
  padding-top: 12px;

  & .col {
    display: flex;

    & .film-name {
      width: 256px;

      & .item {
        font-size: 9px;
        color: #fff;
        background-color: #d2d6dc;
        height: 14px;
        line-height: 14px;
        padding: 0 2px;
        border-radius: 2px;
        display: inline-block;
        margin-bottom: 2px;
      }
      & .name {
        color: #191a1b;
        font-size: 18px;
        height: 24px;
        line-height: 24px;
        margin-right: 7px;
      }
    }

    & .film-grade {
      width: calc(100% - 250px);
      text-align: right;
      color: #ffb232;
      & .grade {
        font-size: 18px;
        font-style: italic;
      }
      & .grade-text {
        font-size: 10px;
      }
    }
  }
  & .grey-text {
    font-size: 13px;
    color: #797d82;
    margin-top: 4px;
  }
  & .film-synopsis {
    margin-top: 12px;
    
  }

  & .toggle {
    text-align: center;
    display: block;
    height: auto;
    width: 20px;
    margin: auto;
    line-height: normal;
    height: 16px;
    img {
      width: 8px;
      margin: auto;
    }
  }
}
.actors {
  margin-top: 10px;
  background-color: #fff;
  height: 193px;
  overflow: hidden;
  & .actors-title-bar {
    width: 100%;
    padding: 15px;
  }
  & .slide-box {
    display: -webkit-box;
    padding-left: 10px;
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;

    & .slide-item {
      width: 85px;
      height: 85px;
      line-height: 40px;
      text-align: center;
      margin-right: 10px;
      position: relative;
      overflow: hidden;
      img{
        width: 100%;
         position: absolute;
         left: 0;
         top: -20%;
      }
    }
    & .name{
      text-align: center;
      font-size: 12px;
      color: #191a1b;
      width: 85px;
      padding-top: 10px;

      & .actors-role{
        font-size: 10px;
        color: #797d82;
      }
    }
  }
  .slide-box::-webkit-scrollbar {
    background-color: transparent;
  }
}

.photos{
  margin-top: 10px;
  
  background-color: #fff;
  & .photos-title-bar{
    height: 62px;
    width: 100%;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    & .claphotos-to-all{
    font-size: 13px;
    color: #797d82;

      & .iconfont{
        font-size: 13px;
        color: #797d82;
      }
    }
    & .photos-title-text{
      font-size: 16px;
      text-align: left;
      color: #191a1b;
    }
  }
  & .slide-box {
      display: -webkit-box;
      overflow-x: scroll;
     
      // -webkit-overflow-scrolling: touch;
      // -ms-overflow-style: none;
      overflow: -moz-scrollbars-none;
      padding-left: 10px;
      
      & .slide-item {
            width: 20%;
            height: 40px;
            line-height: 40px;
            text-align: center;
        }
      & .slide-item{
        width:150px;
        height: 100px;
        margin-right: 10px;
        & img{
          width: 100%;
        }
      }
  }
  & .slide-box::-webkit-scrollbar {
      background-color: transparent;
  }
}

.goSchedule{
    position: fixed;
    bottom: 0;
    left: 0;
    height: 49px;
    width: 100%;
    text-align: center;
    background-color: #ff5f16;
    color: #fff;
    font-size: 16px;
    line-height: 49px;
}
.film-header{
  position: fixed;
  top: 0;
  .title{
    font-size: 17px;
    line-height: 44px;
    width: 100vw;
    text-align: center;
  }
  & .goBack{
    position: absolute;
    height: 30px;
    top: 5px;
    left: 5px;
    width: 30px;
    background: rgba(255, 255, 255, 0.324);
    border-radius: 50%;
    text-align: center;
    line-height:30px ;
  }
}

</style>